/**
 * fileName:  FruitArgumentReader.java
 * author:  huaimi
 * Company:  Cloudland Studio
 * Createdate:  2014-6-12 下午9:07:30
 *
 * All rights Reserved, Designed By cloudland Copyright(C) 2010-2011
 *   
 * Modification  History:
 *     Date           Author        Version        
 * -------------------------------------------
 * 2014-6-12          huaimi            1.0        
 *
 * Why & What is modified:
 * 1.0: 文件创建
 */
package org.cloudland.commercial.masterdata.store.read;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.cloudland.commercial.masterdata.store.DatabaseReader;
import org.cloudland.commercial.masterdata.store.entity.FruitArgumentEntity;
import org.cloudland.jdbc.ibatis.masterdata.entity.ArgumentRelationEntity;
import org.cloudland.jdbc.ibatis.masterdata.handler.ArgumentRelationMapper;
import org.springframework.stereotype.Component;

 /**
 * 水果分类与参数关系领域层仓储写实现类，实现了分类与参数关系的查询
 * @ClassName  FruitArgumentReader
 * @author  huaimi
 * @version  %I%, %G%
 * @see  
 * @since   JDK1.6
 *
 */
@Component
public class FruitArgumentReader implements DatabaseReader<FruitArgumentEntity>
{
	@Resource(name="argumentRelationMapper")
	private ArgumentRelationMapper argumentRelationMapper;
	
	public List<FruitArgumentEntity> FindArgumentRelationByFruitId(String fruitId)
	{
		List<ArgumentRelationEntity> daoArray = argumentRelationMapper.findArgumentRelationByFruitId(fruitId);
		
		List<FruitArgumentEntity> result = new ArrayList<FruitArgumentEntity>(daoArray.size());
		String[] costId = null;
		FruitArgumentEntity argumentEntity = null;
		for (ArgumentRelationEntity daoEntity : daoArray) {
			costId = null;
			if (null != daoEntity.getCostId() && daoEntity.getCostId().length() > 0) {
				costId = daoEntity.getCostId().split(",");
				argumentEntity = new FruitArgumentEntity(daoEntity.getArgumentId(), costId);
			} else {
				argumentEntity = new FruitArgumentEntity(daoEntity.getArgumentId());
				argumentEntity.setCostCustom(daoEntity.getCostCustom());
			}
			
			result.add(argumentEntity);
		}
		
		return result;
	}
}
